import axios from 'axios'
import { weatherAppid, weatherAppsecret } from '@/env'

export function getWeather () {
  return new Promise((resolve, reject) => {
    return axios.get(`https://www.tianqiapi.com/api?version=v1&appid=${weatherAppid}&appsecret=${weatherAppsecret}`).then(res => {
      if (res.status === 200) {
        resolve(res.data)
      } else {
        reject(new Error('Call weather api error'))
      }
    }).catch(() => reject(new Error('Call weather api error')))
  })
}
